﻿using STHPMS1.Common.C_Entity;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore;
using STHPMS1.ICore.I_Core;
using STHPMS1.ICore.I_UI;
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace STHPMS1.Web.W_Controller.Decision.Repair
{
    [RoutePrefix("api/repairlar")]
    public class Dr_RepairLarController : STHPMS1.Web.W_Core.MyController
    {
        [Route("")]
        [Route("page/{page?}", Name = "GetRepairLarByPage")]
        [Route("rows/{rows?}")]
        [Route("page/{page?}/rows/{rows?}")]
        public IHttpActionResult Get(string anniname = null, string analy_year = null, int page = 1, int rows = 10)
        {
            int p = page;
            int s = rows;

            PagingInfo info = new PagingInfo();
            info.PageIndex = p > 0 ? p - 1 : 0;
            info.PageSize = s;
            info.TotalRecords = 0;

            Expression<Func<Dr_Repair_Lar, bool>> exp = null;
            if (anniname != null && anniname.ToString().Length > 0 && analy_year != null && analy_year.ToString().Length > 0)
                exp = pre => pre.Anni_Name == anniname.ToString() && pre.Analy_Year == analy_year.ToString();

            var data = this.Scene.Bll.Dr_Repair_Lar.Get<Dr_Repair_Lar>(exp, info).ToArray();
            if (data == null) return NotFound();

            var result = new { rows = data, total = info.TotalRecords };

            return Ok(result);
        }



        /// <summary>
        /// 大修数据添加
        /// </summary>
        /// <param name="rdwayid"></param>
        [Route("insert")]
        [HttpGet]
        public void Insert(string anniname, string analy_year)
        {
            this.Scene.Bll.Dr_Repair_Lar.Insert(anniname, analy_year);
        }

       
    }
}